<?php
namespace app\admin\controller;
use think\Db;


class Order extends Common
{
    public function lists()
    {
        $info['searchWords'] = input('param.searchWords/s','');
        $info['order_status'] = input('param.order_status/d',5);
        $info['region_id'] = input('param.region_id/d',0);
        $where = [
            ['order_number|true_name|phone','like',"%{$info['searchWords']}%"],
            ['is_delete','=',0]
        ];
        if($info['order_status'] !=5){
            $where[] =  ['order_status','=',$info['order_status']];
        }
        if($info['region_id']){
            $where[] =  ['region_id','=',$info['region_id']];
        }

        if(ADMINTYPE ==2){
            $where[] =  ['region_id','=',$this->adminInfo["region_id"]];
        }
        $list = Db::name('orders')
            ->where($where)
            ->field('id,headimgurl,region_name,appointment_date,appointment_time,order_number,address_type,type_name,true_name,phone,weight_type,order_status,create_time')
            ->order('id','desc')->paginate(10,false,[
                'query'=>$info
            ]);;
        $fetch = [
            'list'=>$list,
            'info'=>$info,
            'region'=>Db::name('region')->field('id,name')->select(),
        ];
        if(ADMINTYPE ==1){
            $fetch['region'] = Db::name('region')->field('id,name')->select();
        }
        return view('',$fetch);
    }
    //评价管理
    public function appraise(){
        $where = [];

        if(ADMINTYPE ==2){
            $orderS = Db::name('orders')->where("region_id",$this->adminInfo["region_id"])->field("id")->select();
            $in  = [];
            foreach ($orderS as $v){
                $in[] = $v["id"];
            }
            $where[] = ["order_id","in",$in];
        }
       $list =  Db::name('order_appraise')
           ->where($where)
            ->field('id,headimgurl,order_id,receiving,come,service,`describe`,accept_user_name,create_time,(service + `receiving` + come) as total')
            ->order('id','desc')->paginate(10,[]);
       return view('',['list'=>$list]);
    }
    public function info($id){
        $where = [
            ['is_delete','=',0],
            ['id','=',$id],
        ];
        $info = Db::name('orders')
            ->where($where)->find();
        if($info['order_status'] ==2){
            $info['details'] =Db::name('order_detail')->where('order_id',$info['id'])->field('small_type_name,price,number,unit')->select();
        }
        $info['images'] = json_decode($info['images']);
        $info['all_type'] = json_decode($info['all_type'],true);
        return view('',['info'=>$info]);
    }
}